Repository navigation
Open a conversation whose tool result is a list of parts - #2874
Draft
davidmckayv wants to merge 2 commits into
Draft
davidmckayv wants to merge 2 commits into
davidmckayv wants to merge 2 commits into
Conversation
AG-UI 1.0 lets a tool result be a string or a list of content parts, and the stock ag_ui_claude_sdk adapter sends a list whenever a Claude tool result is anything but one plain text block: Read on a picture or a PDF, or an MCP tool that answered in several parts. The transcript read every result as a string, so the first .trim() on a list threw inside ChatTranscript's render and blanked the page, and a stored history holding one could not be opened again. The transcript projection now turns a tool message's content into text once, for every reader: a string as it came, a list as its text parts with a short line for a picture, document or other part, anything else as JSON. The result readers in tool-result.ts and the gallery and sandboxed renderers take any value. One message or step that still cannot be read now costs that row alone, not the conversation.
The result is drawn as markdown, which runs single lines together, so two text parts read as one sentence (Found 2 pages Ribbon diagrams Protein folds). Found by the end-to-end run.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
A conversation with a connected Bot blanked the whole page with
TypeError: e.trim is not a functionwhen one of the Bot's tool results was a list of content parts instead of a string. AG-UI 1.0 allows both (ToolMessageSchema,ToolCallResultEvent), and the stockag_ui_claude_sdkadapter sends a list whenever a Claude tool result is anything but one plain text block: Read on a picture or a PDF, or an MCP tool that answered in several parts. The transcript read every result as a string. The throw was inChatTranscript's own render (dropRepeatedAppCards->cardApp->asText), outside every row'sToolRenderBoundary. The page went blank live, and a conversation holding one could not be opened again.chat-messages.ts: a tool message'scontentis turned into text once, where results are gathered, so every reader downstream gets a string. A string stays exactly as it came, so refusal markers and JSON envelopes read the same. A list becomes its text parts, a paragraph each, with a short line for anything else ("Returned an image.", "Returned a document.", "Returned an audio clip.", "Returned a video.", "Returned a file."). Any other value is shown as JSON.tool-result.ts:asTextand the readers built on it (refusalOf,forDisplay,flaggedFailure,browserCallFailed,cutOffStep,unofferedTool,toolResultFailed, and the envelope helpers) take any value.gallery-tools.tsx,sandboxed-tools.tsx: the stored-refusal check calledprops.result?.startsWith. It now reads the result as text first.coding-tools.tsxalready goes throughcodingOutcome->cutOffStep/asText, so the change above covers it. CopilotKit 1.88 itself flattenstoolMessage.contentwithcontentToTextbefore a renderer sees it.shared/tool-steps.ts:settledno longer calls.trim()on a result that is not a string.toVisibleChatItemsprojects each message on its own, andcardAppreads each step on its own. One that still throws is logged and costs that row alone, so the rest of the conversation shows.App only: no API or database change.
Red / green
app/tests/tool-result-parts.test.tsxuses the tool message the realag_ui_claude_sdk0.2.4 produces. It was printed by running the adapter's ownbuild_agui_tool_messageandhandle_tool_result_blockon theToolResultBlockClaude Code hands it. Each case goes throughreadableTurns,toVisibleChatItems,dropRepeatedAppCardsand a renderedChatTranscript:model2.png, "Returned an image." and the replyOn
main(b086b40): 0 pass, 5 fail. Each fails withTypeError: text.trim is not a functionfromasTextviacardApp, or, for the backstop, with the throw escapingChatTranscript. On this branch: 5 pass, 0 fail.End to end
The real product on a fresh test machine, in Chrome (Chromium) and Safari (WebKit). Each browser connected a Bot from New Bot > Bring your own agent > An agent you already run. The agent was a stand-in that knows nothing about OpenBot. It answers every run with the events
ag_ui_claude_sdk0.2.4 streams for that turn, in the adapter's order:RUN_STARTED, the tool call,TOOL_CALL_RESULT, the answer,MESSAGES_SNAPSHOT,RUN_FINISHED. TheTOOL_CALL_RESULTand the snapshot's tool message are the ones the adapter's own code prints, byte for byte.Two turns per browser: a Read of a picture (one image part), and an MCP tool that answered in two text parts. For each turn, the answer arrives live with no page error, and the stored events keep the result as the list the agent sent. The conversation then opens again, the step opens, and the result shows. Screenshots were taken at 1440 and 390 px, light and dark, with nothing scrolling sideways.
main(b086b40): both browsers fail at the first turn. The page shows "This page couldn't be shown" withTypeError: text.trim is not a function.The first green run turned up one layout bug, which the second commit fixes. Two text parts ran together into one line ("Found 2 pages Ribbon diagrams Protein folds"), because the result is drawn as markdown. Each part is now its own paragraph, and the run was repeated on the fixed head.
main)Phone width, dark, and the live turn
Changelog
Conversations.